package cn.wolfcode.wolf2w.strategy.controller;

import cn.wolfcode.wolf2w.common.core.domain.R;
import cn.wolfcode.wolf2w.common.security.annotation.InnerAuth;
import cn.wolfcode.wolf2w.common.security.annotation.RequiresLogin;
import cn.wolfcode.wolf2w.strategy.api.domain.Strategy;
import cn.wolfcode.wolf2w.strategy.api.domain.StrategyCatalog;
import cn.wolfcode.wolf2w.strategy.api.domain.StrategyContent;
import cn.wolfcode.wolf2w.strategy.query.StrategyQuery;
import cn.wolfcode.wolf2w.strategy.service.IStrategyCatalogService;
import cn.wolfcode.wolf2w.strategy.service.IStrategyService;
import com.baomidou.mybatisplus.core.metadata.IPage;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

/**
 * 攻略管理 Controller
 * 
 * @author dalang
 * @date 2023-11-23
 */
@RestController
@RequestMapping("strategies")
public class StrategyController {
    @Autowired
    private IStrategyService strategyService;

    @Autowired
    private IStrategyCatalogService strategyCatalogService;
    /**
     * 攻略管理详情
     */
    @GetMapping("/detail/{id}")
    public R<Strategy> detail(@PathVariable Long id) {
        Strategy strategy = strategyService.queryById(id);
        return R.ok(strategy);
    }
    /**
     * 攻略管理 列表
     */
    @GetMapping("/query")
    public R<IPage<Strategy>> query(StrategyQuery qo) {
        IPage<Strategy> page = strategyService.queryPage(qo);
        return R.ok(page);
    }

    /**
     * 概况 列表
     */
    @GetMapping("/catalogList")
    public R<List<StrategyCatalog>> catalogList(Long destId) {
        List<StrategyCatalog> list = strategyCatalogService.queryCatalogList(destId);
        return R.ok(list);
    }

    /**
     * 文章内容
     */
    @GetMapping("/content")
    public R<StrategyContent> content(Long id) {
        return R.ok(strategyService.getContent(id));
    }

    /**
     * 浏览数+1
     */
    @PostMapping("/viewnumIncr")
    public R<Map<String,Object>> viewnumIncr(Long sid) {
        Map<String,Object> hash = strategyService.viewnumIncr(sid);
        return R.ok(hash);
    }

    /**
     * 评论数+1
     */
    @PostMapping("/replynumIncr")
    public R<Map<String,Object>> replynumIncr(Long sid) {
        Map<String,Object> hash = strategyService.replynumIncr(sid);
        return R.ok(hash);
    }

    /**
     * 分享数+1
     */
    @PostMapping("/sharenumIncr")
    public R<Map<String,Object>> sharenumIncr(Long sid) {
        Map<String,Object> hash = strategyService.sharenumIncr(sid);
        return R.ok(hash);
    }

    /**
     * 收藏数+1
     */
    @RequiresLogin
    @PostMapping("/favor")
    public R<Map<String,Object>> favor(Long sid) {
        Map<String,Object> hash = strategyService.favor(sid);
        return R.ok(hash);
    }

    /**
     * 用户是否收藏
     */
    @RequiresLogin
    @GetMapping("/isUserFavor")
    public R<Boolean> isUserFavor(Long sid,Long uid) {
        Boolean ret = strategyService.isUserFavor(sid,uid);
        return R.ok(ret);
    }

    /**
     * 顶+1
     */
    @RequiresLogin
    @PostMapping("/thumbsup")
    public R<Map<String,Object>> thumbsup(Long sid) {
        Map<String,Object> ret = strategyService.thumbsup(sid);
        return R.ok(ret);
    }

    /**
     * 前三攻略
     */
    @GetMapping("/viewnnumTop3")
    public R<List<Strategy>> viewnnumTop3(Long destId) {
        return R.ok(strategyService.viewnnumTop3(destId));
    }



    /*****************************************对外暴露Fegin接口**********************************************/
    /**
     * Feign 接口
     */
    @GetMapping("/feign/list")
    public R<List<Strategy>> feignList() {
        return R.ok(strategyService.list());
    }
    @InnerAuth
    @GetMapping("/feign/{id}")
    public R<Strategy> feignGet(@PathVariable Long id) {
        return R.ok(strategyService.getById(id));
    }

    @InnerAuth
    @PostMapping("/feign/redisDataPersistenceHandle")
    public R<?> redisDataPersistenceHandle() {
        strategyService.updateCache();
        return R.ok();
    }
}
